package mygame;

import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.*;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

public class pyramid
{
    private float zLength, xWidth, yHeight, xPos,yPos,zPos;
    public pyramid()
    {
        
    }
    public pyramid(float xWidth,float yHeight,float zLength,float xPos,float yPos,float zPos)
    {
        
        this.xWidth = xWidth;
        this.yHeight = yHeight;
        this.zLength = zLength;
        this.xPos = xPos;
        this.yPos = yPos;
        this.zPos = zPos;
        
    }
    public Spatial createPyramid()
    {
        Mesh rPyramidMesh = new Mesh();
        Vector3f [] vertices = new Vector3f[5];
        vertices[0] = new Vector3f(xPos,yPos,zPos);
        vertices[1] = new Vector3f(xPos+xWidth,yPos,zPos);
        vertices[2] = new Vector3f(xPos+xWidth,yPos,zPos+zLength);
        vertices[3] = new Vector3f(xPos,yPos,zPos+zLength);
        vertices[4] = new Vector3f(xPos+(xWidth/2),yPos+yHeight,zPos+(zLength/2));
        
        
        //texture coordinates
        Vector2f[] texCoord = new Vector2f[5];
        texCoord[0] = new Vector2f(0,0);
        texCoord[1] = new Vector2f(1,0);
        texCoord[2] = new Vector2f(0,1);
        texCoord[3] = new Vector2f(1,1);
        texCoord[4] = new Vector2f(0,0);
        //index faces: bottom,front, right, back, left
         int [] indexes = {2,1,0, 0,3,2,
             0,1,4, 
             1,2,4,
             3,4,2, 
             0,3,4};
        rPyramidMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        rPyramidMesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
        rPyramidMesh.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indexes));
        rPyramidMesh.updateBound(); 
        
        Spatial rPyramidGeom = new Geometry("ourmesh",rPyramidMesh);
        //Common/MatDefs/Misc/ShowNormals.j3md rainbow colors
       // Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        //mat.setColor("Color",ColorRGBA.Red);
        //rPyramidGeom.setMaterial(mat);
        //rootNode.attachChild(rPyramidGeom);
        return rPyramidGeom;
    }
}